<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 规则：就近原则
        // 1、当前作用域存在
        let age = 20;
        function  fn(){
            let age = 30;
            console.log(age);
        }
        fn();
        // 2、当前作用域不存在 上级存在
        let sex = '男';
        function fn2(){
            console.log(sex);
        }
        fn2();
        // 3、当前作用域不存在 上级也不存在
        let girlFriend = '刘亦菲';
        function fn3(){
            function fn4(){
                console.log('girlFriend')
                console.log(username);
            }
            fn4();
        }
        fn3();
    </script>
</body>
</html>